package com.fosu.dao;

import com.fosu.domain.User;
import com.fosu.domain.UserAndRole;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName 用户和角色关系持久层
 * @Description TODO
 * @Author 夜天冥
 * @Date 2020/11/9 21:36
 * @Version 1.0
 */
@Mapper
@Repository
public interface UserAndRoleDao {
    /**
     * @Author 夜天冥
     * @Description //TODO 查询所有用户跟角色的关系 * @Date  2020/11/9
     * @Param
     * @return List<UserAndRole>
     **/
    @Select("select * from user_role")
    @Results(id = "userAndRoleMap", value = {
            @Result(id = true, property = "userId", column = "user_id"),
            @Result(property = "roleId", column = "role_id"),
    })
    List<UserAndRole> findAll();

    /**
     * 根据用户id查找对应的角色id
     *
     * @param userId 用户id
     * @return UserAndRoleMap 用户跟角色关系对象
     */
    @Select("select * from user_role where user_id=#{userId}")
    @ResultMap(value = {"userAndRoleMap"})
    List<UserAndRole> findUserAndRoleById(int userId);
}
